<template>
<div id="pageBox">
<div class="c_select_box2">
    <span class="title">保险公司</span>
    <input type="text" class="input_text" placeholder="保险公司" tabIndex="1" id="companyInput" maxLength="100" v-on:focus="addCurr" v-on:blur="checkCompanyName" v-model.trim = "companyName">
    <router-link to="/insuranceCompany" tag="button" class="btn_more">…</router-link>
    <i class="icon_error">出错提示:</i>
    <span class="error_tips">请输入正确的保险公司名称</span>
</div>
<div class="c_select_box2">
    <span class="title">产品名称</span>
    <input type="text" class="input_text" placeholder="产品名称" tabIndex="2" id="productInput" maxLength="1000" v-on:focus="addCurr" v-on:blur="checkProductName" v-model.trim = "productName">
    <router-link :to="{ path: '/insProductList', query: { companyId: companyId }}" tag="button" class="btn_more">…</router-link>
    <i class="icon_error">出错提示:</i>
    <span class="error_tips">请输入正确的产品名称</span>
</div>
<div class="c_select_box" id="insuranceType">
    <span class="title">保险类别</span>
    <select id="selectProInput" v-on:change="selectPro" v-model.trim = "insuranceType">
      <option value="保险类别" disabled="disabled">保险类别</option>
      <option value="车险">车险</option>
      <option value="家财险">家财险</option>
      <option value="意健险">意健险</option>
      <option value="健康险">健康险</option>
      <option value="寿险">寿险</option>
      <option value="养老险">养老险</option>
      <option value="其它">其它</option>
    </select>
    <i class="icon_error">出错提示:</i>
    <span class="error_tips">请选择保险类别</span>
</div>
<div class="c_input_box">
    <span class="title">保单号</span>
    <input type="text" class="input_text" tabIndex="7" placeholder="保单号(至少输入后4位)" id="pilicyNumInput" v-on:focus="addCurr" v-on:blur="checkPolicyNum" v-model.trim = "policyNum">
    <button type="button" class="btn_del" v-on:click="delPolicyNum">x</button>
    <i class="icon_error">出错提示:</i>
    <span class="error_tips">至少输入保单号后4位</span>
</div>
<h3 class="other_title">以下是附加信息，非必填</h3>
<div class="c_select_box3">
    <span class="title">生效日期</span>
    <input type="date" class="input_text" tabIndex="3" placeholder="生效日期" id="startDateInput" v-on:focus="addCurr" v-on:blur="checkStartDate" v-model.trim = "startDate">
    <i class="icon_error">出错提示:</i>
    <span class="error_tips">请选择正确的生效日期</span>
</div>
<div class="c_select_box3">
    <span class="title">满期日期</span>
    <input type="date" class="input_text" tabIndex="4" placeholder="满期日期" id="lastDateInput" v-on:focus="addCurr" v-on:blur="checkLastDate" v-model.trim = "lastDate">
    <i class="icon_error">出错提示:</i>
    <span class="error_tips">请选择正确的满期日期</span>
</div>
<div class="c_input_box">
    <span class="title">保额（元）</span>
    <input type="number" class="input_text" tabIndex="5" pattern="[0-9]*" placeholder="保额" id="insNumInput" maxLength="17" v-on:focus="addCurr" v-on:keypress="checkNum" v-on:blur="checkInsuranceNum" v-model.trim = "insuranceNum">
    <button type="button" class="btn_del" v-on:click="delInsuranceNum">x</button>
    <i class="icon_error">出错提示:</i>
    <span class="error_tips">请输入正确的保额</span>
</div>
<div class="c_input_box">
    <span class="title">保费（元）</span>
    <input type="number" class="input_text" tabIndex="6" pattern="[0-9]*" placeholder="保费" id="payNumInput" v-on:focus="addCurr" v-on:keypress="checkNum" v-on:blur="checkPayNum" v-model.trim = "payNum">
    <button type="button" class="btn_del" v-on:click="delPayNum">x</button>
    <i class="icon_error">出错提示:</i>
    <span class="error_tips">请输入正确的保费</span>
</div>
<button type="button" class="c_smt_btn" v-on:click="submitForm">提交</button>
<toast v-if="isError" v-bind:tipText='errorTips'></toast>
<loading v-bind:loading='isLoading'></loading>
</div>
</template>

<script>
import toast from '../components/toast.vue'
import loading from '../components/loading.vue'
import config from '../config'
export default {
  name: 'addForm',
  components: {
      toast,
      loading
  },
  props:[''],
  data () {
    return {
      companyName: "",
      companyNameBac: "",
      companyId: "",
      productName: "",
      productNameBac: "",
      productId: "",
      insuranceTypeId: "",
      insuranceType: "保险类别",
      startDate: "",
      lastDate: "",
      insuranceNum: "",
      payNum: "",
      policyNum: "",
      policyId: "",
      isFinish: true,
      from: "",
      addType: "",
      isError:false,
      errorTips:"",
      urlEditForm: "",
      isLoading: false,
      timer:''
    }
  },
  watch: {
    companyName:function (){
        //输入过滤，只能输入中文和英文大小写
        let val = this.companyName;
        if(typeof val === 'string'){
          if(val.length && val.length > 0){
            if(/^[\u4E00-\u9FA5A-Za-z]/.test(val.charAt(val.length-1))){
            }
            else{
              val = val.substr(0, val.length-1);
              this.companyName = val;
            }
          }
        }

        window.sessionStorage.companyName = val;

        this.addType = "2";
        if(this.companyName !== this.companyNameBac || this.urlEditForm === "company" || this.urlEditForm === "product" ){
          $("#productInput").siblings(".btn_more").hide();
        }else{
          $("#productInput").siblings(".btn_more").show();
        }
    },
    productName:function (){
        window.sessionStorage.productName = this.productName;
        this.addType = "2";
    },
    insuranceType:function (){
        let _this = this;
        window.sessionStorage.insuranceType = _this.insuranceType;
        switch (_this.insuranceType) {
          case "车险":
            window.sessionStorage.insuranceTypeId = "01";
            _this.insuranceTypeId = "01";
            $("#selectProInput").siblings(".title").css({"display":"block"});
            break;
          case "家财险":
            window.sessionStorage.insuranceTypeId = "02";
            _this.insuranceTypeId = "02";
            $("#selectProInput").siblings(".title").css({"display":"block"});
            break;
          case "意健险":
            window.sessionStorage.insuranceTypeId = "03";
            _this.insuranceTypeId = "03";
            $("#selectProInput").siblings(".title").css({"display":"block"});
            break;
          case "健康险":
            window.sessionStorage.insuranceTypeId = "04";
            _this.insuranceTypeId = "04";
            $("#selectProInput").siblings(".title").css({"display":"block"});
            break;
          case "寿险":
            window.sessionStorage.insuranceTypeId = "05";
            _this.insuranceTypeId = "05";
            $("#selectProInput").siblings(".title").css({"display":"block"});
            break;
          case "养老险":
            window.sessionStorage.insuranceTypeId = "06";
            _this.insuranceTypeId = "06";
            $("#selectProInput").siblings(".title").css({"display":"block"});
            break;
          case "其它":
            window.sessionStorage.insuranceTypeId = "07";
            _this.insuranceTypeId = "07";
            $("#selectProInput").siblings(".title").css({"display":"block"});
            break;
          default:
            //window.sessionStorage.insuranceTypeId = "07";
            $("#selectProInput").siblings(".title").css({"display":""});
            break;
        }
    },
    startDate:function (){
        window.sessionStorage.startDate = this.startDate;
        let _this = this;
        let el  = $("#startDateInput");
        if(this.startDate === ""){
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.removeClass("select_color");
            // this.isFinish = false;
        }else{
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.addClass("select_color");
        }
    },
    lastDate:function (){
        window.sessionStorage.lastDate = this.lastDate;
        let _this = this;
        let el  = $("#lastDateInput");
        if(_this.lastDate === ""){
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.removeClass("select_color");
        }else{
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.addClass("select_color");
        }
    },
    insuranceNum:function (){
        window.sessionStorage.insuranceNum = this.insuranceNum;
    },
    payNum:function (){
        window.sessionStorage.payNum = this.payNum;
    },
    policyNum:function (){
        window.sessionStorage.policyNum = this.policyNum;
    }
  },
  computed:{
    
  },
  methods:{
    checkInput:function (len,maxLen,idName){
        let el = $("#"+idName).parent("div");
        let _this = this;
        if(len < maxLen){
            //为了删除按钮能实现功能
            setTimeout(function (){
                el.removeClass("curr");
                el.addClass("error");
                _this.isFinish = false;
            }, 50);
        }else{
            setTimeout(function (){
                el.removeClass("curr");
                el.removeClass("error");
            }, 50);
        }
        if(len > 0){
          $("#"+idName).siblings(".title").css("display","block");
        }else{
          $("#"+idName).siblings(".title").css("display","");
        }
        return false;
    },
    addCurr:function (event){
        let _this = this;
        $(event.target).parent("div").addClass("curr");
        $(event.target).parent("div").removeClass("error");
        clearTimeout(_this.timer);
        _this.timer = setTimeout(function (){
          //保额、保费输入框 向上滚动
          if($(event.target).attr('id') == 'insNumInput' || $(event.target).attr('id') == 'payNumInput'){
              document.getElementById('pageBox').scrollTop = 10000;
          }
        },300);
    },
    checkCompanyName:function (){
        this.checkInput(this.companyName.length,2,"companyInput");
        if(this.companyName.length > 0){

        }
    },
    checkProductName:function (){
        this.checkInput(this.productName.length,2,"productInput");
    },
    //选择保险
    selectPro:function (event){
        let el  = $("#selectProInput");
        if(this.insuranceType === "保险类别" || this.insuranceType === ""){
            el.parent("div").removeClass("curr");
            el.parent("div").addClass("error");
            el.removeClass("select_color");
            this.isFinish = false;
        }else{
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.addClass("select_color");
        }
    },
    //日期比较
    compareDate:function (date1,date2){
        var oDate1 = new Date(date1);
        var oDate2 = new Date(date2);
        if(oDate1.getTime() > oDate2.getTime()){
            return true;
        } else {
            return false;
        }
    },
    checkStartDate:function (){
        let _this = this;
        let el  = $("#startDateInput");
        if(this.startDate === ""){
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.removeClass("select_color");
            // this.isFinish = false;
        }else{
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.addClass("select_color");
        }

        //验证比较日期
        if(_this.lastDate !== "" && _this.startDate !== "" && typeof _this.lastDate === 'string' && typeof _this.startDate === 'string'){
          let isStartDate = _this.compareDate(_this.startDate,_this.lastDate);
          if(isStartDate){
            $("#startDateInput").parent('div').addClass("error");
            this.isFinish = false;
          }else{
            $("#startDateInput").parent('div').removeClass("error");
            $("#lastDateInput").parent('div').removeClass("error");
          }
        }
    },
    checkLastDate:function (){
        let _this = this;
        let el  = $("#lastDateInput");
        if(_this.lastDate === ""){
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.removeClass("select_color");
        }else{
            el.parent("div").removeClass("curr");
            el.parent("div").removeClass("error");
            el.addClass("select_color");
        }

        //验证比较日期
        if(_this.lastDate !== "" && _this.startDate !== "" && typeof _this.lastDate === 'string' && typeof _this.startDate === 'string'){
          let isStartDate = _this.compareDate(_this.startDate,_this.lastDate);
          let date = new Date();
          let today = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
          let lastday = (new Date(_this.lastDate)).getTime();
          today = (new Date(today)).getTime();
          if(isStartDate){
            $("#lastDateInput").parent('div').addClass("error");
            this.isFinish = false;
          }else if(lastday<today){
            $("#lastDateInput").parent('div').addClass("error");
            this.isFinish = false;
          }else{
            $("#startDateInput").parent('div').removeClass("error");
            $("#lastDateInput").parent('div').removeClass("error");
          }
        }
    },
    checkPolicyNum:function (){
        this.checkInput(this.policyNum.length,4,"pilicyNumInput");
    },
    checkInsuranceNum:function (){
      let _this = this;
      let numVal = _this.insuranceNum;
      let input = $("#insNumInput");
      let el = input.parent("div");
      let elDom = input.get(0);

      //如初始值为空字符串时，不做处理
      if(numVal == '' && !elDom.validity.badInput){
        setTimeout(function (){
                el.removeClass("right");
                el.removeClass("curr");
                el.removeClass("error");
            }, 50);
        input.siblings(".title").css({"display":""});
      }
      //如果是合法数字类型，做处理
      else if(!elDom.validity.badInput){
        numVal = Number(numVal);
        //保留2位小数
        numVal = numVal.toFixed(2);
        _this.insuranceNum = numVal;
        //超过限额
        if (numVal >= 100000000000000) {
          setTimeout(function (){
              el.removeClass("right");
              el.removeClass("curr");
              el.addClass("error");
              _this.isFinish = false;
          }, 50);
        }
        //符合限额
        else if(numVal < 100000000000000 && numVal > 0){
          //为了删除按钮能实现功能
          setTimeout(function (){
              el.addClass("right");
              el.removeClass("curr");
              el.removeClass("error");
          }, 50);
          input.siblings(".title").css({"display":""});
        }
        else{
          setTimeout(function (){
                el.removeClass("right");
                el.removeClass("curr");
                el.removeClass("error");
            }, 50);
          input.siblings(".title").css({"display":""});
        }
      }
      //其他情况判断
      else{
        setTimeout(function (){
              el.removeClass("right");
              el.removeClass("curr");
              el.addClass("error");
              _this.isFinish = false;
          }, 50);
      }
    },
    checkPayNum:function (){
      let _this = this;
      let numVal = _this.payNum;
      let input = $("#payNumInput");
      let el = input.parent("div");
      let elDom = input.get(0);

      //如初始值为空字符串时，不做处理
      if(numVal == '' && !elDom.validity.badInput){
        setTimeout(function (){
                el.removeClass("right");
                el.removeClass("curr");
                el.removeClass("error");
            }, 50);
        input.siblings(".title").css({"display":""});
      }
      //如果是合法数字类型，做处理
      else if(!elDom.validity.badInput){
        numVal = Number(numVal);
        //保留2位小数
        numVal = numVal.toFixed(2);
        _this.payNum = numVal;
        //超过限额
        if (numVal >= 100000000000000) {
          setTimeout(function (){
              el.removeClass("right");
              el.removeClass("curr");
              el.addClass("error");
              _this.isFinish = false;
          }, 50);
        }
        //符合限额
        else if(numVal < 100000000000000 && numVal > 0){
          //为了删除按钮能实现功能
          setTimeout(function (){
              el.addClass("right");
              el.removeClass("curr");
              el.removeClass("error");
          }, 50);
          input.siblings(".title").css({"display":""});
        }
        else{
          setTimeout(function (){
                el.removeClass("right");
                el.removeClass("curr");
                el.removeClass("error");
            }, 50);
          input.siblings(".title").css({"display":""});
        }
      }
      //其他情况判断
      else{
        setTimeout(function (){
              el.removeClass("right");
              el.removeClass("curr");
              el.addClass("error");
              _this.isFinish = false;
          }, 50);
      }
    },
    delInsuranceNum:function (){
        this.insuranceNum = "";
        $(event.target).siblings(".input_text").focus();
    },
    delPayNum:function (event){
        this.payNum = "";
        $(event.target).siblings(".input_text").focus();
    },
    delPolicyNum:function (event){
        this.policyNum = "";
        $(event.target).siblings(".input_text").focus();
    },
    submitForm:function (){
        let _this = this;
        //判断前2个表单项是否是自定义的,3自选列表,2是自定义
        if(_this.companyNameBac === _this.companyName && _this.productNameBac === _this.productName && _this.urlEditForm !== "company" && _this.urlEditForm !== "product"){
          _this.addType = "3";
        }else{
          _this.addType = "2";
        }

        //验证表单
        _this.isFinish = true;
        _this.checkCompanyName();
        _this.checkProductName();
        _this.selectPro();
        _this.checkStartDate();
        _this.checkLastDate();
        _this.checkInsuranceNum();
        _this.checkPayNum();
        _this.checkPolicyNum();

        let ajaxAPI = function (oprType,fnCallBack){
          let req = [{"osType": "3"}];
          //必填项
          let arr = {
            "companyName": _this.companyName,
            "productName": _this.productName,
            "typeId": _this.insuranceTypeId,
            "typeName": _this.insuranceType,
            "addType": _this.addType,
            "policyNo": _this.policyNum,
            "companyId": _this.companyId,
            "effectDate": _this.startDate+'',
            "expireDate": _this.lastDate+'',
            "premiumAmount": _this.payNum+'',
            "assuredAmount": _this.insuranceNum+'',
            "productId": _this.productId
          };

          //编辑保单页需要此ID
          if(_this.from == "policyPage"){
            arr.policyId = _this.policyId;
          }

          req.push(arr);
          req = JSON.stringify(req);
          _this.postRequest(oprType,req,fnCallBack);
        }

        //页面AJAX请求回调
        let fnCallBackAddForm = function (data){
          if(data.resultStatus == "1000"){
            _this.isLoading = false;
            //获取保单ID
            if(data.result.id){
              _this.policyId = data.result.id;
            }
            //跳转保单列表页
            if(_this.from == "policyPage"){
              _this.showTips("添加保单成功",function (){
                let url = "patoa://pingan.com/insurance/detail/edit/success";
                window.App.call(['openURL'], null, null, {url: url});
              });
            }
            //跳转到传图片页
            else{
              _this.showTips("添加保单成功",function (){
                let url = "patoa://pingan.com/insurance/upload_image?policyId="+_this.policyId;
                window.App.call(['openURL'], null, null, {url: url});
              });
            }
          }
          else if(data.resultStatus == "9999"){
            _this.isLoading = false;
            _this.showTips(data.tips ? data.tips : "登录超时，请重新登录",function (){
              YztApp.callLogin();
            });
            // let thisUrl = window.location.href;
            // window.App.call(["getSSOLogin"],function(e){},function(e){},{"redirectURL":thisUrl});
          }
          else{
            _this.isLoading = false;
            _this.showTips(data.tips ? data.tips : "服务器繁忙，请稍后再试",function (){
              YztApp.callLogin();
            });
          }
        };

        //等获取(_this.from)
        setTimeout(function (){
          if(_this.isFinish){
            _this.isLoading = true;
            //编辑页面逻辑
            if(_this.from == "policyPage"){
              ajaxAPI("updatePolicyInfo",fnCallBackAddForm);
            }else{
              ajaxAPI("addPolicyInfo",fnCallBackAddForm);
            }
          }
        },100);

        //埋点
        window.YztApp.ubt('我的保险','保单信息输入页面_点击_提交',{'保险名称':_this.productName,'险种类别':_this.insuranceType,'保单号':_this.policyNum,'主险保额':_this.insuranceNum,'保费':_this.payNum,'满期日期':_this.lastDate});    
    },
    postRequest: function (operationType , reqData, callback) {
        //AJAX
        //url: "/toa-mgw/rest/webgateway",
        let _this = this;
        $.ajax({
          url:config.url,
          data: {
              operationType:operationType,
              requestData: reqData
          },
          type: "POST",
          cache: false,
          timeout: 8000,
          dataType: "json",
          beforeSend: function(){

          },
          success: function(response){
              typeof response == 'string' ? response = $.parseJSON(response) : response;
              callback(response);
          },
          error: function () {
            _this.isLoading = false;
            _this.showTips('服务器繁忙，请稍后再试');
          }
        });
    },
    getSSOLogin: function (callBackFn) {
        //获取任意门登录参数，传给GP获取登录态
        // var timer;
        // var _this = this;
        // clearTimeout(timer);
        // //登录超时设置
        // timer = setTimeout(function () {
        //     window.isH5Login = false;
        // }, 600000);
        // if(!window.isH5Login){
        //     YztApp.getSSOTicket(function (status,data){
        //         var reqData = '[{"osType": "3"},'+data+']';
        //         if(status === "success"){
        //             _this.postRequest("mamcLogin", reqData, function (reponse) {
        //                 if (reponse.resultStatus == '1000') {
        //                     window.isH5Login = true;
        //                 }
        //                 else{
        //                     _this.showTips(data.tips ? data.tips : "登录超时，请重新登录");
        //                     YztApp.callLogin();
        //                     //let thisUrl = window.location.href;
        //                     //window.App.call(["getSSOLogin"],function(e){},function(e){},{"redirectURL":thisUrl});
        //                 }
        //                 if(typeof callBackFn == "function"){
        //                     callBackFn();
        //                 }
        //             });
        //         }else{
        //             window.isH5Login = false;
        //             if(typeof callBackFn == "function"){
        //                 callBackFn();
        //             }
        //             _this.showTips(data.tips ? data.tips : "用户登录信息获取失败");
        //         }
        //         console.log('Ticket:'+data);
        //         _this.ticket = data;
        //     });
        // }else{
        //     if(typeof callBackFn == "function"){
        //         callBackFn();
        //     }
        // }

        var _this = this;
        YztApp.getSSOTicket(function (status,data){
            var reqData = '[{"osType": "3"},'+data+']';
            if(status === "success"){
                _this.postRequest("mamcLogin", reqData, function (reponse) {
                    if (reponse.resultStatus == '1000') {
                    }
                    else{
                        _this.showTips("登录超时，请重新登录",function (){
                          YztApp.callLogin();
                        });
                        //let thisUrl = window.location.href;
                        //window.App.call(["getSSOLogin"],function(e){},function(e){},{"redirectURL":thisUrl});
                    }
                    if(typeof callBackFn == "function"){
                        callBackFn();
                    }
                });
            }else{
                // if(typeof callBackFn == "function"){
                //     callBackFn();
                // }
                _this.showTips("用户登录信息获取失败，请重新登录试试？",function (){
                  YztApp.callLogin();
                });
            }
        });
    },
    //报错提示
    showTips:function (text,fnCallBack){
      let _this = this;
      _this.errorTips = text;
      _this.isError = true;
      window.setTimeout(function (){
        _this.isError = false;
        if(fnCallBack){
          fnCallBack();
        }
      },1000);
    },
    checkNum:function (event){
      //禁止非数字键盘输入
      if(!((event.keyCode>=48 && event.keyCode<=57) || event.keyCode == 45 || event.keyCode == 43)){
        console.log(event.keyCode);
        return false;
      }
    }
  },
  mounted:function(){
      //请求native登录
      var _this = this;
      if(!!_this.$route.query.urlPolicyNum){
          _this.policyId = _this.$route.query.urlPolicyNum;
          let cont = 0;
          window.sessionStorage.urlFrom = "policyPage";

          let fnCallBack = function (data){
            //let url = "patoa://pingan.com/insurance/upload_image?policyId="+_this.policyNum;
            if(data.resultStatus == "1000"){
              //读取保单信息
               //公司名称
               data.result.policyInfo.companyName ? _this.companyName = data.result.policyInfo.companyName : "";
               //公司ID
               data.result.policyInfo.companyId ? _this.companyId  = data.result.policyInfo.companyId : "";
               //产品名称
               data.result.policyInfo.productName ? _this.productName = data.result.policyInfo.productName : "";
               //保险类型ID
               data.result.policyInfo.typeId ? _this.insuranceTypeId = data.result.policyInfo.typeId : "";
               //保险类型
               data.result.policyInfo.typeName ? _this.insuranceType = data.result.policyInfo.typeName : "";
               //生效日期
               data.result.policyInfo.effectDate ? _this.startDate = data.result.policyInfo.effectDate : "";
               //满期日期
               data.result.policyInfo.expireDate ? _this.lastDate = data.result.policyInfo.expireDate : "";
               //保额
               data.result.policyInfo.assuredAmount ? _this.insuranceNum = Number(data.result.policyInfo.assuredAmount) : "";
               //保费
               data.result.policyInfo.premiumAmount ? _this.payNum = Number(data.result.policyInfo.premiumAmount) : "";
               //保单号
               data.result.policyInfo.policyNo ? _this.policyNum = data.result.policyInfo.policyNo : "";
               //保单ID
               data.result.policyInfo.id ? _this.policyId = data.result.policyInfo.id : "";

               //隐藏Loading图标
               _this.isLoading = false;

               //备份表单信息，留作提交的时候做比较
                _this.companyNameBac = _this.companyName;
                _this.productNameBac = _this.productName;

                window.sessionStorage.policyId = _this.policyId;
                window.sessionStorage.companyName = _this.companyName;
                window.sessionStorage.companyId = _this.companyId;
                window.sessionStorage.productName = _this.productName;
                window.sessionStorage.insuranceTypeId = _this.insuranceTypeId;
                window.sessionStorage.insuranceType = _this.insuranceType;
                window.sessionStorage.startDate = _this.startDate;
                window.sessionStorage.lastDate = _this.lastDate;
                window.sessionStorage.insuranceNum = _this.insuranceNum;
                window.sessionStorage.payNum = _this.payNum;
                window.sessionStorage.policyNum = _this.policyNum;
                window.sessionStorage.policyId = _this.policyId;

                //金额格式重新设置
                _this.checkInsuranceNum();
                _this.checkPayNum();

                //初始化显示组件Title
                if(_this.companyName !== ""){
                  $("#companyInput").siblings(".title").css({"display":"block"});
                }
                if(_this.productName !== ""){
                  $("#productInput").siblings(".title").css({"display":"block"});
                }
                if(_this.policyNum !== ""){
                  $("#pilicyNumInput").siblings(".title").css({"display":"block"});
                }
                if(_this.insuranceNum !== ""){
                  $("#insNumInput").siblings(".title").css({"display":"block"});
                }
                if(_this.payNum !== ""){
                  $("#payNumInput").siblings(".title").css({"display":"block"});
                }

                if(_this.insuranceType !== "保险类别" && _this.insuranceType !== ""){
                    $("#selectProInput").addClass("select_color");
                }

                if(_this.startDate !== ""){
                  $("#startDateInput").addClass("select_color");
                }

                if(_this.lastDate !== ""){
                  $("#lastDateInput").addClass("select_color");
                }
            }
            else{
                //请求2次，如果第一次登录失败，再请求一次
                if(cont == 0){
                  cont += 1;
                  getPolicy();
                }
                else if(data.resultStatus == "9999"){
                  //隐藏Loading图标
                  _this.isLoading = false;

                  _this.showTips(data.tips ? data.tips : "登录超时，请重新登录",function (){
                    YztApp.callLogin();
                  });
                  // let thisUrl = window.location.href;
                  // window.App.call(["getSSOLogin"],function(e){},function(e){},{"redirectURL":thisUrl});
                }else{
                  //隐藏Loading图标
                  _this.isLoading = false;
                  _this.showTips(data.tips ? data.tips : '保单信息获取失败，请稍后再试',function (){
                    YztApp.callLogin();
                  });
                }
            }
          };
          let req = [{"osType": "3"}];
          let arr = {
            "policyId": _this.policyId
          };
          req.push(arr);
          req = JSON.stringify(req);

          let getPolicy = function (){
            _this.isLoading = true;
            _this.postRequest("getPolicyDetail",req,fnCallBack);
          }

          //任意门登录
          _this.getSSOLogin();
          //等待登录请求500毫秒后请求数据接口，防止无登录态接口异常
          setTimeout(getPolicy,500);
      }else{
        _this.getSSOLogin();
      }

      //读取展示表单缓存
      //注意：window.sessionStorage.insuranceType 的值一定要与选择框里的值对应匹配，否则就会报错
      window.sessionStorage.companyName ? _this.companyName = window.sessionStorage.companyName : "";
      window.sessionStorage.companyId ? _this.companyId = window.sessionStorage.companyId : "";
      window.sessionStorage.productName ? _this.productName = window.sessionStorage.productName : "";
      window.sessionStorage.insuranceTypeId ? _this.insuranceTypeId = window.sessionStorage.insuranceTypeId : "";
      window.sessionStorage.insuranceType ? _this.insuranceType = window.sessionStorage.insuranceType : "";
      window.sessionStorage.startDate ? _this.startDate = window.sessionStorage.startDate : "";
      window.sessionStorage.lastDate ? _this.lastDate = window.sessionStorage.lastDate : "";
      window.sessionStorage.insuranceNum ? _this.insuranceNum = window.sessionStorage.insuranceNum : "";
      window.sessionStorage.payNum ? _this.payNum = window.sessionStorage.payNum : "";
      window.sessionStorage.policyNum ? _this.policyNum = window.sessionStorage.policyNum : "";
      window.sessionStorage.urlFrom ? _this.from = window.sessionStorage.urlFrom : "";
      window.sessionStorage.policyId ? _this.policyId = window.sessionStorage.policyId : "";
      //备份表单信息，留作提交的时候做比较
      _this.companyNameBac = _this.companyName;
      _this.productNameBac = _this.productName;

      //存储编辑页路由
      _this.$route.query.urlEditForm ? _this.urlEditForm = _this.$route.query.urlEditForm : "";
      //自选跳过来的，光标获取焦点
      switch (_this.urlEditForm) {
        case "company":
          $("#companyInput").focus();
          break;
        case "product":
          $("#productInput").focus();
          break;
        default:
          // statements_def
          break;
      }

      _this.checkInsuranceNum();
      _this.checkPayNum();

      //金额格式重新设置
      setTimeout(function (){
        //自定义表单的时候隐藏产品的选择按钮
        if(_this.urlEditForm){
          $("#productInput").siblings(".btn_more").hide();
        }
        //初始化显示组件Title
        if(_this.companyName !== ""){
          $("#companyInput").siblings(".title").css({"display":"block"});
        }
        if(_this.productName !== ""){
          $("#productInput").siblings(".title").css({"display":"block"});
        }
        if(_this.policyNum !== ""){
          $("#pilicyNumInput").siblings(".title").css({"display":"block"});
        }
        if(_this.insuranceNum+'' !== ""){
          $("#insNumInput").siblings(".title").css({"display":"block"});
        }
        if(_this.payNum+'' !== ""){
          $("#payNumInput").siblings(".title").css({"display":"block"});
        }
        if(_this.insuranceType !== "保险类别" && _this.insuranceType !== ""){
            $("#selectProInput").addClass("select_color");
        }
        if(_this.startDate !== ""){
          $("#startDateInput").addClass("select_color");
        }
        if(_this.lastDate !== ""){
          $("#lastDateInput").addClass("select_color");
        }
      },100);
  }
}
</script>

<style type="text/css">
#pageBox{
  width:100%;
  height:100%;
  overflow:auto;
  -webkit-overflow-scrolling: touch;
/*   overflow-scrolling: touch; */
}
/* #pageCont{
  height:21rem;
} */
::-webkit-scrollbar{
  width:0px;
}
::-webkit-input-placeholder {
color: #CCC;
font-size:0.426667rem;
} 
#pageContent{

}
.c_input_box {
width: 8.666667rem;
margin: 0 auto;
margin-top: 0.64rem;
position: relative;
border: 1px solid #CCC;
border-radius: 0.266667rem;
}
.c_input_box .input_text {
width: 7.533334;
border: 0;
color: #4A4A4A;
height: 1.466667rem;
font-size: 0.426667rem;
font-weight: normal;
padding-left: 0.40rem;
font-weight: normal;
background: 0;
border: 0;
}
.c_input_box.curr {
border-color: #4A90E2;
}
.c_input_box .title,
.c_input_box .title {
color: #CCC;
font-size: 0.373333rem;
height: 0.373333rem;
background-color: #FFF;
position: absolute;
left: 0.266667rem;
top: -0.186667rem;
z-index: 1;
padding: 0 12px;
display: inline-block;
}
.c_input_box.curr .btn_del {
width: 0.8rem;
height: 1.44rem;
position: absolute;
right: 0.16rem;
top: 0;
z-index: 1;
background: url("../images/del.png") no-repeat 0.173333rem 0.48rem;
background-size: 0.48rem 0.48rem;
border: 0;
text-indent: -9999px;
overflow: hidden;
display: inline-block;
}
.c_input_box.error {
border-color: #E60012;
}
.c_input_box.error .icon_error {
width: 0.8rem;
height: 1.44rem;
position: absolute;
right: 0.16rem;
top: 0;
z-index: 1;
background: url("../images/error.png") no-repeat 0.173333rem 0.48rem;
background-size: 0.48rem 0.48rem;
border: 0;
text-indent: -9999px;
overflow: hidden;
display: inline-block;
}
.c_input_box.error .error_tips {
position: absolute;
top: -0.693333rem;
background: #000;
opacity: 0.7;
height: 1.013333rem;
line-height: 1.013333rem;
font-size: 0.32rem;
display: inline-block;
z-index: 1;
border-radius: 0.133333rem;
right: 0;
font-size: 0.373333rem;
color: #FFF;
padding: 0 0.32rem;
}

.c_input_box .title,
.c_input_box .btn_del,
.c_input_box .error_tips,
.c_input_box .icon_error{
display: none;
}

.c_input_box.curr .title,
.c_input_box.error .title,
.c_input_box.right .title{
display: inline-block;
}

.c_select_box {
width: 8.666667rem;
height: 1.44rem;
border: 1px solid #CCC;
border-radius: 0.266667rem;
margin: 0 auto;
margin-top: 0.64rem;
position: relative;
}
.c_select_box select {
width: 8.333334rem;
border: 0;
color: #AAA;
height: 1.44rem;
font-size: 0.426667rem;
padding-left: 0.40rem;
border-radius: 0.266667rem;
font-weight: normal;
background: url("../images/cner.jpg") no-repeat 7.973333rem 0.6rem;
background-size: 0.346667rem 0.213333rem;
-webkit-appearance:none;
-webkit-tap-highlight-color:#FAFAFA;
}
.c_select_box .select_color {
color: #4A4A4A;
}

.c_select_box.curr {
border-color: #4A90E2;
}
.c_select_box.error {
border-color: #E60012;
}
.c_select_box .title,
.c_select_box .icon_error,
.c_select_box .error_tips{
display: none;
}
.c_select_box .title,
.c_select_box .title{
color: #CCC;
font-size: 0.373333rem;
height: 0.373333rem;
background-color: #FFF;
position: absolute;
left: 0.266667rem;
top: -0.186667rem;
z-index: 1;
padding: 0 12px;
display: none;
}
.c_select_box.curr .title,
.c_select_box.error .title{
display: inline-block;
}

.c_select_box.error .btn_more{
display: none;
}
.c_select_box.error .icon_error {
width: 0.8rem;
height: 1.44rem;
position: absolute;
right: 0.16rem;
top: 0;
z-index: 1;
background: url("../images/error.png") no-repeat 0.173333rem 0.48rem;
background-size: 0.48rem 0.48rem;
border: 0;
text-indent: -9999px;
overflow: hidden;
display: inline-block;
}
.c_select_box.error .error_tips {
position: absolute;
top: -0.693333rem;
background: #000;
opacity: 0.7;
height: 1.013333rem;
line-height: 1.013333rem;
font-size: 0.32rem;
display: inline-block;
z-index: 1;
border-radius: 0.133333rem;
right: 0;
font-size: 0.373333rem;
color: #FFF;
padding: 0 0.32rem;
}
.c_select_box.error select{
    background:0;
}

.c_select_box2 {
width: 8.666667rem;
height: 1.44rem;
border: 1px solid #CCC;
border-radius: 0.266667rem;
margin: 0 auto;
margin-top: 0.64rem;
position: relative;
}
.c_select_box2 .input_text {
width: 7.533334rem;
color: #4A4A4A;
height: 1.44rem;
font-size: 0.426667rem;
font-weight: normal;
padding-left: 0.40rem;
font-weight: normal;
background: 0;
border: 0;
}
.c_select_box2 .select_color{
color:#4A4A4A;
}
.c_select_box2 .btn_more {
width: 0.8rem;
height: 1.44rem;
position: absolute;
right: 0;
top: 0;
z-index: 1;
background: url("../images/cner.jpg") no-repeat 0.16rem 0.6rem;
background-size: 0.346667rem 0.213333rem;
border: 0;
text-indent: -9999px;
overflow: hidden;
display: inline-block;
}
.c_select_box2.curr {
border-color: #4A90E2;
}
.c_select_box2.error {
border-color: #E60012;
}
.c_select_box2 .icon_error,
.c_select_box2 .error_tips{
display: none;
}
.c_select_box2 .title,
.c_select_box2 .title {
color: #CCC;
font-size: 0.373333rem;
height: 0.373333rem;
background-color: #FFF;
position: absolute;
left: 0.266667rem;
top: -0.186667rem;
z-index: 1;
padding: 0 12px;
display: none;
}

.c_select_box2.curr .title,
.c_select_box2.error .title{
  display: inline-block;
}
.c_select_box2.error .btn_more{
display: none;
}
.c_select_box2.error .icon_error {
width: 0.8rem;
height: 1.44rem;
position: absolute;
right: 0.16rem;
top: 0;
z-index: 1;
background: url("../images/error.png") no-repeat 0.173333rem 0.48rem;
background-size: 0.48rem 0.48rem;
border: 0;
text-indent: -9999px;
overflow: hidden;
display: inline-block;
}
.c_select_box2.error .error_tips {
position: absolute;
top: -0.693333rem;
background: #000;
opacity: 0.7;
height: 1.013333rem;
line-height: 1.013333rem;
font-size: 0.32rem;
display: inline-block;
z-index: 1;
border-radius: 0.133333rem;
right: 0;
font-size: 0.373333rem;
color: #FFF;
padding: 0 0.32rem;
}

.c_select_box3 {
width: 8.666667rem;
height: 1.44rem;
border: 1px solid #CCC;
border-radius: 0.266667rem;
margin: 0 auto;
margin-top: 0.64rem;
position: relative;
}
.c_select_box3 .input_text {
width: 8.333334rem;
color: #CCC;
height: 1.44rem;
font-size: 0.426667rem;
font-weight: normal;
padding-left: 0.40rem;
font-weight: normal;
-webkit-appearance:none;
background: url("../images/cner.jpg") no-repeat 7.973333rem 0.6rem;
background-size: 0.346667rem 0.213333rem;
border: 0;
}
.c_select_box3 .select_color{
color:#4A4A4A;
}
.c_select_box3 .btn_more {
width: 0.8rem;
height: 1.44rem;
position: absolute;
right: 0;
top: 0;
z-index: 1;
background: url("../images/cner.jpg") no-repeat 0.16rem 0.6rem;
background-size: 0.346667rem 0.213333rem;
border: 0;
text-indent: -9999px;
overflow: hidden;
display: inline-block;
}
.c_select_box3.curr {
border-color: #4A90E2;
}
.c_select_box3.error {
border-color: #E60012;
}
.c_select_box3 .icon_error,
.c_select_box3 .error_tips{
display: none;
}
.c_select_box3 .title,
.c_select_box3 .title {
color: #CCC;
font-size: 0.373333rem;
height: 0.373333rem;
background-color: #FFF;
position: absolute;
left: 0.266667rem;
top: -0.186667rem;
z-index: 1;
padding: 0 12px;
display: inline-block;
}
.c_select_box3.error .btn_more{
display: none;
}
.c_select_box3.error .icon_error {
width: 0.8rem;
height: 1.44rem;
position: absolute;
right: 0;
top: 0;
z-index: 1;
background: url("../images/error.png") no-repeat 0.173333rem 0.48rem;
background-size: 0.48rem 0.48rem;
border: 0;
text-indent: -9999px;
overflow: hidden;
display: inline-block;
}
.c_select_box3.error .error_tips {
position: absolute;
top: -0.693333rem;
background: #000;
opacity: 0.7;
height: 1.013333rem;
line-height: 1.013333rem;
font-size: 0.32rem;
display: inline-block;
z-index: 1;
border-radius: 0.133333rem;
right: 0;
font-size: 0.373333rem;
color: #FFF;
padding: 0 0.32rem;
}


.c_smt_btn {
width: 6.4rem;
height: 1.266667rem;
background-color: #cfa767;
color: #FFF;
font-size: 0.533333rem;
border-radius: 42px;
border: 0;
margin: 0 auto;
display: block;
margin-top: 0.64rem;
margin-bottom:1rem;
}
.c_surance_list {
margin-left: 5px;
margin-top: 75px;
height: 800px;
overflow: auto;
}
.c_surance_list img {
width: 100%;
height: 100%;
}
.c_surance_list li {
float: left;
border: 1px solid #CCC;
width: 2.933333rem;
height: 2.933333rem;
overflow: hidden;
margin-left: 0.266667rem;
margin-bottom: 0.266667rem;
}
.c_surance_list button {
width: 2.933333rem;
height: 2.933333rem;
background: url("../images/upload.png") no-repeat center 0.666667rem;
background-size: 1.106667rem 1.106667rem;
position: relative;
border:0;

}
.c_surance_list button span{
color: #4a90e2;
font-size: 27px;
position: absolute;
left: 50%;
margin-left: -54px; 
top: 2.16rem;
z-index: 1;
}
.c_esc_btn{
color: #4a90e2;
font-size: 0.533333rem;
margin: 0 auto;
display: block;
text-align: center;
margin-top: 1.066667rem;
border:0;
background: 0;
}
#box{
width: 6.4rem;
height: 1.266667rem;
background: #F60;
}
.other_title{
  width: 8.666667rem;
  margin:0 auto;
  font-size: 0.373333rem;
  text-indent: 0.333333rem;
  margin-top: 0.29rem;
  color: #9B9B9B;
}
</style>
